package cn.tuling.example;

/**
 * 在外观模式中，当增加或移除子系统时需要修改外观类，这违背了“开闭原则”。如果引入抽象外观类，则在一定程度上解决了该问题
 */
public class FacadeTest {
}

class SubSystem1 {
    public void method() {
        System.out.println("子系统1的方法被执行");
    }
}


class SubSystem2 {
    public void method() {
        System.out.println("子系统2的方法被执行");
    }
}

class SubSystem3 {
    public void method() {
        System.out.println("子系统3的方法被执行");
    }
}

interface Facade {
    void method();
}

class ConcreteFacade1 implements Facade {

    private SubSystem1 subSystem1;
    private SubSystem2 subSystem2;

    public ConcreteFacade1(SubSystem1 subSystem1, SubSystem2 subSystem2) {
        this.subSystem1 = subSystem1;
        this.subSystem2 = subSystem2;
    }

    @Override
    public void method() {
        subSystem1.method();
        subSystem2.method();
    }
}

class ConcreteFacade2 implements Facade {

    private SubSystem2 subSystem2;
    private SubSystem3 subSystem3;

    public ConcreteFacade2(SubSystem2 subSystem2, SubSystem3 subSystem3) {
        this.subSystem2 = subSystem2;
        this.subSystem3 = subSystem3;
    }

    @Override
    public void method() {
        subSystem2.method();
        subSystem3.method();
    }
}
